package com.fr.report.core.headerfooter;

import com.fr.base.DefaultValues;
import com.fr.base.FRContext;
import com.fr.base.FRFont;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.GraphHelper;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.geom.Dimension2D;
import java.util.StringTokenizer;

public class TextHFElement extends AbstractHFElement
{
  private String text;
  private FRFont frFont;

  public TextHFElement()
  {
    this("", null);
  }

  public TextHFElement(String paramString, FRFont paramFRFont)
  {
    this.text = null;
    this.frFont = null;
    setText(paramString);
    if (paramFRFont == null)
    {
      DefaultValues localDefaultValues = FRContext.getDefaultValues();
      paramFRFont = localDefaultValues.getFRFont();
    }
    setFRFont(paramFRFont);
  }

  public String getText()
  {
    return this.text;
  }

  public void setText(String paramString)
  {
    this.text = paramString;
  }

  public FRFont getFRFont()
  {
    return this.frFont;
  }

  public void setFRFont(FRFont paramFRFont)
  {
    this.frFont = paramFRFont;
  }

  public Dimension2D getSize()
  {
    String str1 = getText();
    StringTokenizer localStringTokenizer = new StringTokenizer(str1, "\n");
    int i = str1.length();
    for (int j = 0; j < i; ++j)
    {
      k = str1.charAt(j);
      if (k == 13)
      {
        if ((j < i - 1) && (str1.charAt(j + 1) == '\n'))
        {
          localStringTokenizer = new StringTokenizer(str1, "\r\n");
          break;
        }
        localStringTokenizer = new StringTokenizer(str1, "\r");
        break;
      }
      if (k == 10)
        break;
    }
    j = localStringTokenizer.countTokens();
    int k = 0;
    FontMetrics localFontMetrics = GraphHelper.getFontMetrics(getFRFont());
    while (localStringTokenizer.hasMoreElements())
    {
      String str2 = localStringTokenizer.nextToken();
      if (str2 == null)
        str2 = "";
      k = Math.max(localFontMetrics.stringWidth(str2), k);
    }
    return new Dimension(k, localFontMetrics.getHeight() * j);
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof TextHFElement) && (ComparatorUtils.equals(this.frFont, ((TextHFElement)paramObject).frFont)) && (ComparatorUtils.equals(this.text, ((TextHFElement)paramObject).text)));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    TextHFElement localTextHFElement = (TextHFElement)super.clone();
    if (getFRFont() != null)
      localTextHFElement.setFRFont((FRFont)getFRFont().clone());
    return localTextHFElement;
  }
}